﻿using System;
using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;

public class DisplayDamageNumber : MonoBehaviour
{
    public int duration = 2;
    
    public GameObject num;
    public GameObject plus;
    public GameObject minus;

    private void Awake()
    {
        num?.SetActive(false);
        plus?.SetActive(false);
        minus?.SetActive(false);
    }

    public void DrawDamagedNumber(int value)
    {
        StartCoroutine(DisplayNum(value));
    }

    public IEnumerator DisplayNum(int value)
    {
        plus.SetActive(value > 0);
        minus.SetActive(value < 0);
        num.SetActive(true);
        
        num.GetComponent<TextMeshProUGUI>().SetText(Mathf.Abs(value).ToString());
        
        yield return new WaitForSeconds(duration);

        HideNum();
    }

    private void HideNum()
    {
        plus.SetActive(false);
        minus.SetActive(false);
        num.SetActive(false);
    }
}
